package org.refresh.core.intelligence.emf.tests;

import java.util.ArrayList;

import junit.framework.TestCase;

import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.examples.extlibrary.EXTLibraryFactory;
import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
import org.refresh.core.intelligence.Constraint;
import org.refresh.core.intelligence.emf.OCLConstraint;
import org.refresh.core.intelligence.emf.OCLConstraintEvaluator;

/******************************************************************************
 * Copyright (c) 2005, 2006 Jules White.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Jules White - initial API and implementation 
 ****************************************************************************/
public class OCLEvaluatorTest extends TestCase {

	
	public void testSimpleConstraint(){
		OCLConstraintEvaluator eval = new OCLConstraintEvaluator();
		OCLConstraint con = new OCLConstraint("not(self.title = target.title)");
		EXTLibraryFactory fact = EXTLibraryPackage.eINSTANCE.getEXTLibraryFactory();
		Book f1 = fact.createBook();
		Book f2 = fact.createBook();
		Book f3 = fact.createBook();
		f1.setTitle("foo");
		f2.setTitle("foo2");
		f3.setTitle("foo");
		assertTrue(eval.evaluate(f1, f2, con));
		
		OCLConstraint c2 = new OCLConstraint("target.title = target.title");
		ArrayList<Constraint> cons = new ArrayList<Constraint>();
		cons.add(con);
		cons.add(c2);
		ArrayList world = new ArrayList();
		world.add(f2);
		world.add(f3);
		assertTrue(eval.findAll(f1, world, cons).size() == 1);
	}
}
